
define([
	'vue',
	'config',
	'common',
	'../model/upLoadList',
	'moment',
	],function(Vue,config,utils,upLoadList,moment){
	'use strict';
    	
	var guideView=new Vue({
		el:'#app',
		data:{
			items:'',
			detailItems:'',
			pageSize:'',
			page:1
		},
		watch:{
			items: function(to,from){
				if(to.length == 0 && this.items !== ""){
					$('.error404').show();
				}else{
					$('.error404').hide();
				}
			}
		},
		created:function(){
			utils.userToken();
			var _this=this;
			_this.pageSize = parseInt(Math.ceil(($('body').height()-$('.headTitle').height())/44), 10);
			upLoadList.ajax(utils.getWebUrl('artic/list'),{
				article_type_id: 4,
				pageSize: _this.pageSize,
				page: _this.page
			},function(res){
				_this.page++;
				_this.items = res.data.list;
			},function(){
				$('.DataLoading').show();
			},function(){
				$('.DataLoading').hide();
			})

			//详情
			if(window.location.href.match("guideDetail.html")){
				utils.ajax(utils.getWebUrl('artic/get'),{
					id: utils.getQueryVariable('id')
				},'POST',function(res){
					_this.detailItems = res.data;
				},function(){
					$('.DataLoading').show();
				},function(){
					$('.DataLoading').hide();
				})
			}
		},
		directives: {
		  scroll: {
		    inserted: function (el, binding){
		      var binding =binding;
		      window.addEventListener('scroll',function() {
		       		var fnc = binding.value;   
   					fnc();
		      })
		    }
		  }
		},
		methods:{

			loadMore:function(event){
				var _this = this;
				
				if ((upLoadList.getScrollTop() + upLoadList.getClientHeight() >= upLoadList.getScrollHeight())&&_this.page<_this.totalPage) {

					var data = {
						article_type_id: 4,
						pageSize: _this.pageSize,
						page: _this.page
					}
					_this.page = _this.page+1;
					upLoadList.ajax(utils.getWebUrl('artic/list'),data,function(res){
						_this.items = _this.items.concat(res.data.list);
					})
		        }
			},
			
			toDetail:function(event){
				var id = $(event.currentTarget).data('id');
				window.location.href="guideDetail.html?id="+id;
			}
		}
	})

	return guideView;
});